package com.api.cdfortis.controller;

import com.alibaba.fastjson.JSONObject;
import com.api.cdfortis.dto.PresDataDto;
import com.api.cdfortis.service.IPresDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用于接收微问诊推送的数据处方通知数据
 */
@Controller
@RequestMapping("/push")
public class PresDataController{

    @Autowired
    IPresDataService presDataService;

    /**
     * 6.1 接收处方通知数据
     * @return
     */
    @ResponseBody
    @RequestMapping("/presdata")
    public String presDataHandle(PresDataDto presDataDto) {
        //接收微问诊平台推送的数据，并做处理
        boolean res = presDataService.handle(presDataDto);

        //响应微问诊平台
        JSONObject re = new JSONObject();
        if(res) {
            re.put("returnCode", "SUCCESS");
        } else {
            re.put("returnCode", "FAILED");
        }
        return re.toJSONString();
    }
}
